package com.itheima.utils;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class JwtUtils {
    private static String key="itheima";
    private static  Long expire=4320000L;


    public static String getJwt(Map<String,Object> claims){
        String jwt = Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, key)//签名算法
                .setClaims(claims)  //自定义内容
                .setExpiration(new Date(System.currentTimeMillis() + expire))//令牌有效时间
                .compact();
       return jwt;
    }

    public static Claims jwtParse(String jwt){
        Claims claims = Jwts.parser()
                .setSigningKey(key)
                .parseClaimsJws(jwt)
                .getBody();
       return  claims;
    }
}
